function ListNode(val) {
    this.val = val;
    this.next = null;
}
/**
 * @param {ListNode} headA
 * @param {ListNode} headB
 * @return {ListNode}
 */
var getIntersectionNode = function(headA, headB) {
    let p = headA
    let q = headB
    while (p != q) {
        p = (p == null ? headB : p.next);
        q = (q == null ? headA : q.next);
    }
    return q;
};
let headA = new ListNode(4)
let p1 = new ListNode(1)
let p2 = new ListNode(8)
let p5 = new ListNode(4)
let p6 = new ListNode(5)

headA.next = p1
p1.next = p2
p2.next = p5
p5.next = p6

let headB = new ListNode(5)
let p3 = new ListNode(0)
let p4 = new ListNode(1)
let p7 = new ListNode(8)
let p8 = new ListNode(4)
let p9 = new ListNode(5)
headB.next = p3
p3.next = p4
p4.next = p7
p7.next = p8
p9.next = p9

console.log(getIntersectionNode(headA,headB))
